import { Http } from '../../utils/http'
import { Basics } from '../../model/Basics'

Page({
  getPhoneNumber (e) {
    if(e.detail.errMsg == "getPhoneNumber:ok"){
      this.getNumber(e.detail.iv,e.detail.encryptedData);
    }else{
      console.log("用户取消了授权");
    }
  },

  //获取微信用户的手机号
  getNumber: async function(iv,encryptedData){
    let result = await Basics.get_user_mobile(iv,encryptedData);
    if(result.code == 0){
      this.getPhon(result.data);
    }
  },

  //用户注册
  getPhon:async function(mobile){
  let result = await Basics.get_user_register_mobile(mobile);
  if(result.code == 0){
    wx.setStorageSync('register',1);
    wx.setStorageSync('phone',result.data);
    wx.switchTab({
      url: '/pages/home/index',
    })
  }else{
    wx.showToast({
      title: result.msg,
      icon: 'success',
      duration: 3000
    });
  }
  console.log(result.msg);
 }
 
})